package com.onpositive.page.pagerendering;

public class CodeMirrorParserRenderer {

	public static final int XML_TYPE = 0;
	public static final int CSS_TYPE = 1;
	public static final int JS_TYPE = 2;

	private final static String XMLPARSER = "parsexml.js";
	private final static String CSSPARSER = "parsecss.js";
	private final static String JSPARSER = "parsejavascript.js";

	private final static String XMLSTYLE = "codemirror/css/xmlcolors.css";
	private final static String CSSSTYLE = "codemirror/css/csscolors.css";
	private final static String JSSTYLE = "codemirror/css/jscolors.css";

	private final static String PATH = "codemirror/js/";

	public static String getParserContent(String currentDir, int type,
			String contentField) {
		String parser = "";
		String css = currentDir;
		switch (type) {
		case XML_TYPE:
			parser = XMLPARSER;
			css = XMLSTYLE;
			break;
		case CSS_TYPE:
			parser = CSSPARSER;
			css = CSSSTYLE;
			break;
		case JS_TYPE:
			parser = JSPARSER;
			css = JSSTYLE;
			break;
		default:
			parser = XMLPARSER;
		}
		;

		String path = currentDir + PATH;
		css = currentDir + css;

		StringBuilder sb = new StringBuilder();
		sb.append("<script type=\"text/javascript\">\n");
		sb.append("var editor = CodeMirror.fromTextArea('" + contentField
				+ "', {\n");
		sb.append("height: \"400px\",\n"); // 350px
		sb.append("width: \"860px\",\n");// 800px
		sb.append("parserfile: [\"" + parser + "\"],\n");
		sb.append("stylesheet: \"" + css + "\",\n");
		sb.append("path: \"" + path + "\",\n");
		sb.append("continuousScanning: 500,\n");
		sb.append("lineNumbers: false\n");
		sb.append("});\n");
		sb.append("</script>\n");

		return sb.toString();
	}
}
